#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define maxn 10010
using namespace std;
int a[maxn];
int belong[maxn];
int cnt[1000005];
int ans[maxn];
int block;
int temp;
struct node
{
	int l;
	int r;
	int id;
	int t;
}q[maxn],c[maxn];
void del(int pos)
{
	cnt[a[pos]]--;
	if(cnt[a[pos]]==0) temp--;
}
void add(int pos)
{
	cnt[a[pos]]++;
	if(cnt[a[pos]]==1) temp++;
}
bool cmp(node a,node b)
{
	if(a.l==b.l) return a.r<b.r;
	else return a.l<b.l;
}
int main()
{
	int n,m,x,y;
	int numq = 0;
	int numc = 0;
	char s;
	scanf("%d %d",&n,&m);
	block = sqrt(n)+1;
	for(int i = 1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		belong[i] = (i-1)/block;
	}
	for(int i = 1;i<=m;i++)
	{
	//	printf("i = %d\n,m = %d\n",i,m);
		scanf(" %c %d %d",&s,&x,&y);
		if(s=='Q')
		{
			numq++;
			q[numq].l=x;
			q[numq].r=y;
			q[numq].id=numq;
			q[numq].t = i;			
		}
		else 
		{
			numc++;
			c[numc].l = x;
			c[numc].r = y;
			c[numc].t = i;
		}	
	}
	sort(q+1,q+1+numq,cmp);
	int left = 1;
	int right = 0;
	temp = 0;
	for(int i = 1;i<=numq;i++)
	{
		//printf("*****\n");
		while(left<q[i].l) del(left++);
		while(left>q[i].l) add(--left);
		while(right>q[i].r) del(right--);
		while(right<q[i].r) add(++right);
		
		ans[q[i].id] = temp;
		
	}

	for(int i = 1;i<=numq;i++) printf("%d ",ans[i]);
} 
